package zuoye.Test;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/login")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       this.doPost(req,resp);
    }


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PrintWriter out=resp.getWriter();
        //获得Session 对象
        HttpSession session=req.getSession();
        System.out.println(session.getId());
        String loginname = req.getParameter("username");
        String password = req.getParameter("password");
        req.setCharacterEncoding("utf-8");
        int code;
        String msg;
        if("zzs".equals(loginname)&&"429".equals(password)){
            code = 1;
            msg = "success";
            //System.out.println("登陆成功");
        } else {
            code = 0;
            msg = "failure";
            //System.out.println("登陆失败");
        }

        String jsonResponse = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}";
           out.println(jsonResponse);

    }


}
